layui.config({
    base : "/layui/"
}).extend({
    index: 'lib/index'
}).use(['index','form','jquery', 'table'],function(){
    var form = layui.form,
        table=layui.table,
        admin  = layui.admin;

        table.render({
            elem: '#oem_table'
            ,url: '/oem/queryData'
            ,method:"post"
            ,height: 500
            ,limit:50							//显示数目
            ,limits:[50,100]
            ,cols: [[
                {field:'oemId', title: 'OEMID',width:100, "align":"center"}
                ,{field:'oemName',width:200, title: 'OEM名称',"align":"center"}
                ,{field:'adminDomain',width:200, title: '域名',"align":"center"}
                ,{field:'userName',width:200, title: '登录用户',"align":"center"}
                ,{field:'mobile',width:200, title: '手机号码',"align":"center"}
                ,{field:'createdTime',width:200, title: '创建时间',"align":"center"}
            ]]
            ,request:{
                pageName: 'pageNo' //页码的参数名称，默认：page
                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            where:{}
            ,id: 'oem_table'
            ,page: true
        });

    table.on('tool(oem_table)', function(obj){

        var table_event = obj.event;

        var data = obj.data;
        admin.popup({
            title: '编辑'
            ,shade: 0
            ,anim: -1
            ,offset:"20px"
            ,area: ['80%', '500px']
            ,id: 'layadmin-layer-skin-modify'
            ,skin: 'layui-anim layui-anim-upbit'
            ,content:$("#add_oem_win")
            ,end:function () {
                table.reload('oem_table', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        oemName: $("#oem_name").val(),
                    }
                });
            }
        });

        var table_event = obj.event;

        var data = obj.data;

        if(table_event=="modify_oem"){
            form.val('add_oem_form', {
                "oemId":data.oemId,
                "userId":data.userId,
                "oemName":data.oemName,
                "userName": data.userName,
                "adminDomain": data.adminDomain,
                "mobile":data.mobile
            })

        }

    });

    //添加OEM
    $(".oemAdd_btn").click(function(){

        $("#add_oem_form")[0].reset();
        admin.popup({
            title: '编辑'
            ,shade: 0
            ,anim: -1
            ,offset:"20px"
            ,area: ['80%', '500px']
            ,id: 'layadmin-layer-skin-modify'
            ,skin: 'layui-anim layui-anim-upbit'
            ,content:$("#add_oem_win")
            ,end:function () {
                table.reload('oem_table', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        oemName: $("#oem_name").val(),
                    }
                });
            }
        });



    });

    $("#oem_search_btn").click(function () {
        table.reload('oem_table', {
            page: {
                curr: 1 //重新从第 1 页开始
            }
            ,where: {
                oemName: $("#oem_name").val(),
            }
        });
    });


    /**
     * oem 新增提交
     */
    form.on('submit(addOemOk)',function (data) {

        $.ajax({
            url:"/oem/editOem",
            data:data.field,
            type:"post",
            success:function (result) {
                if (result.code == 1){
                    layer.msg("修改成功",{
                        offset: '32%'
                        ,icon: 1
                        ,time: 3000
                        ,btn: '知道了'
                        ,btnAlign:"c"
                        ,shade:0.4
                        ,yes:function () {
                            table.reload('oem_table', {
                            });
                            layer.closeAll();
                        }
                    })
                }else{
                    layer.msg(result.message,{
                        offset: '32%'
                        ,icon: 2
                        ,time: 3000
                    },function () {
                        layer.closeAll();
                    })
                }

            }
        });
        return false;
    });
})

